package com.jet.merchant.remote.cashier;

import com.jet.core.exception.CustomException;
import com.jet.core.result.ResultCode;
import com.jet.core.result.ResultJson;
import com.jet.merchant.remote.cashier.vo.CashierModeVo;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * @author dcl
 * @since 2025/4/29 10:07
 */
public class MerchantCashierRemoteFallback implements FallbackFactory<MerchantCashierRemoteFeign> {

    @Override
    public MerchantCashierRemoteFeign create(Throwable cause) {
        return new MerchantCashierRemoteFeign() {
            @Override
            public ResultJson<CashierModeVo> getCashierMode(long merchantNo, long storeNo, String accountId) {
                if (cause instanceof CustomException) {
                    ResultJson<?> result = ((CustomException) cause).getResultJson();
                    return ResultJson.failure(result.getCode(), result.getMsg());
                }
                return ResultJson.failure(ResultCode.SERVICE_ERROR);
            }
        };
    }
}
